package unit23.warehouse;

import java.rmi.RemoteException;
import java.util.Enumeration;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NameClassPair;
import javax.naming.NamingException;
import javax.naming.directory.InitialDirContext;

public class WareHouseClient {
	public static void main(String[] args) throws NamingException {
		Context namingContext=new InitialContext();
		
		System.out.print("RMI registry binding：");
		Enumeration<NameClassPair> e=namingContext.list("rmi://localhost/");
		while(e.hasMoreElements()){
			System.out.println(e.nextElement().getName());
		}
		
		String url="rmi://localhost/central_warehouse";
		WareHouse centralWarehouse=(WareHouse) namingContext.lookup(url);
		
		String descr="Mike";
		double price = 0;
		try {
			price = centralWarehouse.getPrice(descr);
		} catch (RemoteException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		System.out.println(descr+": "+price);
		
	}
}
